﻿<div class="container_12">
    <div class="grid_6">
        <div class="module">
            <h2>
                <span>Khai Báo Mytv cho Gpon</span>
            </h2>
            <div class="module-body">
               
                Đơn vị:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.donvi != null)
                {                               
                    @Html.DropDownList("quan_huyen_id", ViewBag.donvi as SelectList, "---Chọn đơn vị---", new { style = "width: 39%" })                               
                }
                
                <br>
                Dslam:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.dslam == null)
                {    
                    @Html.DropDownList("system_id", Enumerable.Empty<SelectListItem>(), "---Chọn Dslam---", new { style = "width: 38.5%" })
                }
                else
                {
                    @Html.DropDownList("system_id", ViewBag.dslam as SelectList, "---Chọn Dslam---", new { style = "width: 38.5%" })
                }
                <br>
                Cổng:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.cong == null)
                {    
                    @Html.DropDownList("cong", Enumerable.Empty<SelectListItem>(), "---Chọn Cổng---", new { style = "width: 38.7%" })
                }
                else
                {
                    @Html.DropDownList("cong", ViewBag.cong as SelectList, "---Chọn Cổng---", new { style = "width: 39%" })

                }&nbsp;
               @* <br />
                 User:<input id="txt_account" name="txt_account" type="text" class="input-medium" />&nbsp;&nbsp;
                 <br />
                 Pass:<input id="txt_account" name="txt_account" type="text" class="input-medium" />&nbsp;&nbsp;
*@
                


                </br>
                </br>
                <input class="submit-green" id="btn_cong" name="btn_cong" type="button" value="Tạo MYTV"  />
            </div>
        </div>
        <!-- module -->
        <div style="clear: both;">
        </div>
    </div>
    <!-- End .grid_6 -->
    <!-- To-do list -->
    <div class="grid_6">
        <div class="module">
            <h2>
                <span>Kết Quả</span></h2>
            <div class="module-body">
                <text id="SNR_textbox" name="SNR_textbox"></text>
                    
            </div>
        </div>
        <!-- module -->
        <div style="clear: both;">
        </div>
    </div>
    <!-- End .grid_6 -->
    <div style="clear: both;">
    </div>
</div>
<script type="text/javascript">
    function reloadpage(data) {
        if (data.indexOf("html") > -1) {
            window.location.reload();
            return true;
        }
        else
            return false;
    }
    function checkdl() {
        if (document.getElementById("doidl").checked) {
            document.getElementById('dungluong').disabled = false;
            document.getElementById('reset_dl_btn').style.visibility = 'visible';
        }
        else {
            document.getElementById('dungluong').disabled = true;
            document.getElementById('reset_dl_btn').style.visibility = 'hidden';
        }
    }
    $("#reset_dl_btn").click(function () {
        $("#reset_dl_dslam").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("ResetDungLuongJSon", "DslamPort")',
            data: { id: document.getElementById("id").value, dslam_type_id: document.getElementById("dslam_type_id").value, dungluong: document.getElementById("dungluong").value, ip: document.getElementById("ip").value, slot: document.getElementById("slot").value, port: document.getElementById("port").value },
            success: function (data) {
                if (reloadpage(data)) return;
                if (data.indexOf("DSLAM") > -1) {
                    $("#reset_dl_dslam").html(data);
                }
                else {
                    $("#reset_dl_dslam").html("Đổi dung lượng cổng DSLAM thành công!");
                }
            }
        })
    });
    $("#btn_account").click(function () {
        if (document.getElementById("txt_account").value.length < 4) {
            alert('Account phải có nhiều hơn 3 ký tự');
            return;
        }
        document.getElementById('div_doidl').style.display = 'none';
        document.getElementById("doidl").checked = false;
        $("#reset_dl_dslam").html("");
        document.getElementById('dungluong').disabled = true;
        $("#SNR_textbox").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("GetSNRJSon", "DslamPort")',
            data: { account: document.getElementById("txt_account").value, cong: '', system_id: '' },
            success: function (data) {

                if (reloadpage(data)) return;
                $("#SNR_textbox").html(data);
                document.getElementById('div_doidl').style.display = 'block';
            }
        })

    });
    $("#btn_cong").click(function () {

        if (document.getElementById("cong").value == "") {
            alert("Phải điền cổng");
            return;
        }
        // document.getElementById('div_doidl').style.display = 'none';
        // document.getElementById("doidl").checked = false;
        // $("#reset_dl_dslam").html("");
        //    document.getElementById('dungluong').disabled = true;
        $("#SNR_textbox").html("<img src='/dslam/Content/ajax-loader.gif'/><br>Vui Lòng Chờ ....");
        $.ajax({
            type: "POST",
            url: '@Url.Action("khaibaomytvjson", "gpon")',
            data: {  cong: document.getElementById("cong").value, system_id: document.getElementById("system_id").value },
            success: function (data) {
                if (reloadpage(data)) return;
                $("#SNR_textbox").html(data);
                // document.getElementById('div_doidl').style.display = 'block';
            }
        })
    });
    $("#quan_huyen_id").change(function () {
       // $("#todanpho_id").html("<option value=''>---Chọn Tổ dân phố---</option>");
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            async: false,
            url: '@Url.Action("getDslamJson", "GPONPort")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
//                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
        $.ajax({
            type: "POST",
            url: '@Url.Action("getcongJson", "GPONPort")',
            data: { system_id: $("#system_id > option:selected").attr("value"), Order: "cong" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn cổng---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#cong").html(items.join(' '));
            }
        })
    });
    $("#quan_huyen_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getKhuvucJson", "GPONPort")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Xã phường---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#xa_phuong_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $("#system_id").html("<option value=''>---Chọn Dslam---</option>");
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getTodanphoJson", "GPONPort")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Tổ dân phố---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#todanpho_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByKhuvucJson", "GPONPort")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#todanpho_id").change(function () {
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByTodanphoJson", "GPONPort")',
            data: { todanpho_id: $("#todanpho_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#system_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getcongJson", "GPONPort")',
            data: { system_id: $("#system_id > option:selected").attr("value"), Order: "cong" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn cổng---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#cong").html(items.join(' '));
            }
        })
    });
</script>
